%
% Author: Vasyl Mykhalchuk
%
function [ ] = saveResultsOfTemporalIntegration( outDir, fileName, sfMin, sfMax, sfMean, hSF, obj_ref, adjVerticesList)
mkdir(outDir);
outDir = strcat(outDir, '\');

dataDir = strcat(outDir, '\data\');
mkdir(dataDir);

nV = obj_ref.nV;
allVertices = reshape(linspace(1, nV, nV), nV, 1);

% SFs
h = 0;
LOG('Exporting... sfMin');
vertexColorList = createColorInfo(allVertices, sfMin, h);
path = getExportFileName(outDir, fileName, exportFileType.kSFMin);
exportPLY( path, obj_ref.vertices, vertexColorList, obj_ref.faces);

LOG('Exporting... sfMax');
vertexColorList = createColorInfo(allVertices, sfMax, h);
path = getExportFileName(outDir, fileName, exportFileType.kSFMax);
exportPLY( path, obj_ref.vertices, vertexColorList, obj_ref.faces);

LOG('Exporting... sfMean');
vertexColorList = createColorInfo(allVertices, sfMean, h);
path = getExportFileName(outDir, fileName, exportFileType.kSFMean);
exportPLY( path, obj_ref.vertices, vertexColorList, obj_ref.faces);

% FPs
LOG('Exctracting FPs from sfMin...');
fps = extractCriticalPoints(sfMin, adjVerticesList);
LOG('Exporting... FPs of min SF');
vertexColorList = createColorInfo(fps, sfMin, h);
path = getExportFileName(outDir, fileName, exportFileType.kFPMin);
exportPLY( path, obj_ref.vertices, vertexColorList, obj_ref.faces);

LOG('Exctracting FPs from sfMax...');
fps = extractCriticalPoints(sfMax, adjVerticesList);
LOG('Exporting... FPs om max SF');
vertexColorList = createColorInfo(fps, sfMax, h);
path = getExportFileName(outDir, fileName, exportFileType.kFPMax);
exportPLY( path, obj_ref.vertices, vertexColorList, obj_ref.faces);

%write data for max sf
path = getExportFileName(dataDir, fileName, exportFileType.kDataFP);
saveData( path, fps, sfMax );

LOG('Exctracting FPs from sfMean...');
fps = extractCriticalPoints(sfMean, adjVerticesList);
LOG('Exporting... sfMax');
vertexColorList = createColorInfo(fps, sfMean, h);
path = getExportFileName(outDir, fileName, exportFileType.kFPMean);
exportPLY( path, obj_ref.vertices, vertexColorList, obj_ref.faces);

% H entropy
h = 1;
LOG('Exporting... hSF');
vertexColorList = createColorInfo(allVertices, hSF, h);
path = getExportFileName(outDir, fileName, exportFileType.kHSF);
exportPLY( path, obj_ref.vertices, vertexColorList, obj_ref.faces);

LOG('Exctracting FPs from hSF...');
fps = extractCriticalPoints(hSF, adjVerticesList);
LOG('Exporting... sfMax');
vertexColorList = createColorInfo(fps, hSF, h);
path = getExportFileName(outDir, fileName, exportFileType.kFPh);
exportPLY( path, obj_ref.vertices, vertexColorList, obj_ref.faces);

% Write the data
path = getExportFileName(dataDir, fileName, exportFileType.kDataFPH);
saveData( path, fps, hSF );


end%function

